package com.topscomm.mpm.script;

import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.mpm.MpmScript;
import com.topscomm.mpm.pojo.MpmProjectAppointmentEntity;
import com.topscomm.mpm.pojo.MpmProjectChangeEntity;
import com.topscomm.mpm.pojo.MpmProjectPlanEntity;
import com.topscomm.mpm.pojo.MpmProjectUniversalChangeEntity;
import com.topscomm.mpm.service.impl.MpmProjectUniversalChangeService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author chengengwei
 * @date 2021-08-20
 * @description: 项目变更通用脚本
 * @modify:
 */
public class MpmProjectUniversalChangeScript extends MpmScript {

    @Transactional
    public void sendMessageToPMO(ITapService service, TapEntity entity) throws Exception {
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        MpmProjectUniversalChangeService changeService= (MpmProjectUniversalChangeService)SpringUtil
                .getBean("mpmProjectUniversalChangeService");
        MpmProjectUniversalChangeEntity changeEntity = changeService.queryById(sourceid);
        changeService.sendMessageToPMO(changeEntity);
    }

    @Transactional
    public void createRecordAfterApproval(ITapService service, TapEntity entity) throws Exception {
        CboApprovalNodeInsEntity nodeins = (CboApprovalNodeInsEntity) entity;
        String sourcetype = ConvertUtil.convertToString(nodeins.getSourcetype());
        String sourceid = ConvertUtil.convertToString(nodeins.getSourceid());
        MpmProjectUniversalChangeService changeService= (MpmProjectUniversalChangeService)SpringUtil
                .getBean("mpmProjectUniversalChangeService");
        changeService.createRecordAfterApproval(sourcetype, sourceid);
    }

}
